/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.flowable.api.model.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.*

/**
 * Tasks
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface TasksApi {


    /**
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of tasks (except for candidateGroupIn which is only available in this POST task query REST service), but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on task and process variables. The taskVariables and processInstanceVariables are both JSON-arrays containing objects with the format as described here.
     */
    @PostMapping("/query/tasks")
    fun queryTasks(
        @RequestBody(required = false) body: TaskQueryRequest?
    ): R<DataResponse<TaskResponse>>

    /**
     * List of tasks
     */
    @GetMapping("/runtime/tasks")
    fun listTasks(
        @RequestParam(name = "name", required = false) name: String?,
        @RequestParam(name = "nameLike", required = false) nameLike: String?,
        @RequestParam(name = "description", required = false) description: String?,
        @RequestParam(name = "priority", required = false) priority: String?,
        @RequestParam(name = "minimumPriority", required = false) minimumPriority: String?,
        @RequestParam(name = "maximumPriority", required = false) maximumPriority: String?,
        @RequestParam(name = "assignee", required = false) assignee: String?,
        @RequestParam(name = "assigneeLike", required = false) assigneeLike: String?,
        @RequestParam(name = "owner", required = false) owner: String?,
        @RequestParam(name = "ownerLike", required = false) ownerLike: String?,
        @RequestParam(name = "unassigned", required = false) unassigned: String?,
        @RequestParam(name = "delegationState", required = false) delegationState: String?,
        @RequestParam(name = "candidateUser", required = false) candidateUser: String?,
        @RequestParam(name = "candidateGroup", required = false) candidateGroup: String?,
        @RequestParam(name = "candidateGroups", required = false) candidateGroups: String?,
        @RequestParam(name = "involvedUser", required = false) involvedUser: String?,
        @RequestParam(name = "taskDefinitionKey", required = false) taskDefinitionKey: String?,
        @RequestParam(name = "taskDefinitionKeyLike", required = false) taskDefinitionKeyLike: String?,
        @RequestParam(name = "taskDefinitionKeys", required = false) taskDefinitionKeys: String?,
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "processInstanceIdWithChildren", required = false) processInstanceIdWithChildren: String?,
        @RequestParam(name = "processInstanceBusinessKey", required = false) processInstanceBusinessKey: String?,
        @RequestParam(
            name = "processInstanceBusinessKeyLike",
            required = false
        ) processInstanceBusinessKeyLike: String?,
        @RequestParam(name = "processDefinitionId", required = false) processDefinitionId: String?,
        @RequestParam(name = "processDefinitionKey", required = false) processDefinitionKey: String?,
        @RequestParam(name = "processDefinitionKeyLike", required = false) processDefinitionKeyLike: String?,
        @RequestParam(name = "processDefinitionName", required = false) processDefinitionName: String?,
        @RequestParam(name = "processDefinitionNameLike", required = false) processDefinitionNameLike: String?,
        @RequestParam(name = "executionId", required = false) executionId: String?,
        @RequestParam(name = "createdOn", required = false) createdOn: String?,
        @RequestParam(name = "createdBefore", required = false) createdBefore: String?,
        @RequestParam(name = "createdAfter", required = false) createdAfter: String?,
        @RequestParam(name = "dueOn", required = false) dueOn: String?,
        @RequestParam(name = "dueBefore", required = false) dueBefore: String?,
        @RequestParam(name = "dueAfter", required = false) dueAfter: String?,
        @RequestParam(name = "withoutDueDate", required = false) withoutDueDate: Boolean?,
        @RequestParam(name = "excludeSubTasks", required = false) excludeSubTasks: Boolean?,
        @RequestParam(name = "active", required = false) active: Boolean?,
        @RequestParam(name = "includeTaskLocalVariables", required = false) includeTaskLocalVariables: Boolean?,
        @RequestParam(name = "includeProcessVariables", required = false) includeProcessVariables: Boolean?,
        @RequestParam(name = "scopeDefinitionId", required = false) scopeDefinitionId: String?,
        @RequestParam(name = "scopeId", required = false) scopeId: String?,
        @RequestParam(name = "scopeType", required = false) scopeType: String?,
        @RequestParam(name = "propagatedStageInstanceId", required = false) propagatedStageInstanceId: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?,
        @RequestParam(name = "candidateOrAssigned", required = false) candidateOrAssigned: String?,
        @RequestParam(name = "category", required = false) category: String?
    ): R<DataResponse<TaskResponse>>

    /**
     * Create Task
     */
    @PostMapping("/runtime/tasks")
    fun createTask(
        @RequestBody(required = false) body: TaskRequest?
    ): R<TaskResponse>

    /**
     * Get a task
     */
    @GetMapping("/runtime/tasks/{taskId}")
    fun getTask(
        @PathVariable("taskId") taskId: String
    ): R<TaskResponse>

    /**
     * Tasks actions
     */
    @PostMapping("/runtime/tasks/{taskId}")
    fun executeTaskAction(
        @PathVariable("taskId") taskId: String,
        @RequestBody(required = false) body: TaskActionRequest?
    ): R<Any>

    /**
     * All request values are optional. For example, you can only include the assignee attribute in the request body JSON-object, only updating the assignee of the task, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the task-value will be updated to null. Example: {"dueDate" : null} will clear the duedate of the task).
     */
    @PutMapping("/runtime/tasks/{taskId}")
    fun updateTask(
        @PathVariable("taskId") taskId: String,
        @RequestBody(required = false) body: TaskRequest?
    ): R<TaskResponse>

    /**
     * Delete a task
     */
    @DeleteMapping("/runtime/tasks/{taskId}")
    fun deleteTask(
        @PathVariable("taskId") taskId: String,
        @RequestParam(name = "cascadeHistory", required = false) cascadeHistory: String?,
        @RequestParam(name = "deleteReason", required = false) deleteReason: String?
    ): R<Any>

    /**
     * List events for a task
     */
    @GetMapping("/runtime/tasks/{taskId}/events")
    fun listTaskEvents(
        @PathVariable("taskId") taskId: String
    ): R<Any>

    /**
     * Get an event on a task
     */
    @GetMapping("/runtime/tasks/{taskId}/events/{eventId}")
    fun getEvent(
        @PathVariable("taskId") taskId: String,
        @PathVariable("eventId") eventId: String
    ): R<EventResponse>

    /**
     * Delete an event on a task
     */
    @DeleteMapping("/runtime/tasks/{taskId}/events/{eventId}")
    fun deleteEvent(
        @PathVariable("taskId") taskId: String,
        @PathVariable("eventId") eventId: String
    ): R<Any>

    /**
     * Get a task form
     */
    @GetMapping("/runtime/tasks/{taskId}/form")
    fun getTaskForm(
        @PathVariable("taskId") taskId: String
    ): R<Any>

    /**
     * List of sub tasks for a task
     */
    @GetMapping("/runtime/tasks/{taskId}/subtasks")
    fun listTaskSubtasks(
        @PathVariable("taskId") taskId: String
    ): R<Any>

    /**
     * This endpoint can be used in 2 ways: By passing a JSON Body (RestVariable or an Array of RestVariable) or by passing a multipart/form-data Object.
    It is possible to create simple (non-binary) variable or list of variables or new binary variable
    Any number of variables can be passed into the request body array.
    NB: Swagger V2 specification does not support this use case that is why this endpoint might be buggy/incomplete if used with other tools.
     */
    @PostMapping("/runtime/tasks/{taskId}/variables")
    fun createTaskVariable(
        @PathVariable("taskId") taskId: String,
        @RequestBody(required = false) body: TaskVariableCollectionResource?,
        @RequestParam(name = "name", required = false) name: String?,
        @RequestParam(name = "type", required = false) type: String?,
        @RequestParam(name = "scope", required = false) scope: String?
    ): R<Any>

    /**
     * Delete all local variables on a task
     */
    @DeleteMapping("/runtime/tasks/{taskId}/variables")
    fun deleteAllLocalTaskVariables(
        @PathVariable("taskId") taskId: String
    ): R<Any>
}